package net.vanchu.mortgagecalculator.mortgage.data.calculator;

/**
 * Created by Granton on 2016/12/21.
 */
public class TBalancedCalculator {

    public static double calRepayPerMonth(double principal, double monthRate, int numberOfMonths) {
        return (double) ((principal * monthRate * Math.pow((monthRate + 1), numberOfMonths)) /
                (Math.pow((1 + monthRate), numberOfMonths) - 1));
    }

    public static double calInterestWithIndex(double principal, double monthRate, double repayPerMonth, int index) {
        return (double) ((principal * monthRate - repayPerMonth) * Math.pow((1 + monthRate), index) + repayPerMonth);
    }

    public static double calPrincipalOneMonthToPay(double repayPerMonth, double interestToPay) {
        return repayPerMonth - interestToPay;
    }

}